package web;

import java.io.File;

public class WebApp {
    private String appsBase;
    private String absoluteAppBase;
    private String contextPath;

    public String getAppsBase() {
        return appsBase;
    }

    public void setAppsBase(String appsBase) {
        this.appsBase = appsBase;
    }

    public String getAbsoluteAppBase() {
        return absoluteAppBase;
    }

    public void setAbsoluteAppBase(String absoluteAppBase) {
        this.absoluteAppBase = absoluteAppBase;
    }

    public String getContextPath() {
        return contextPath;
    }

    public void setContextPath(String contextPath) {
        this.contextPath = contextPath;
    }

    public WebApp(File appsBaseFile, File appDirFile) {
        this.appsBase = appsBaseFile.getAbsolutePath();
        this.absoluteAppBase = appDirFile.getAbsolutePath();
        this.contextPath = relativePath(this.appsBase, this.absoluteAppBase);

//        System.out.println("##### " + this.appsBase + " " + this.absoluteAppBase + " " + this.contextPath);
    }

    // /root/abc   /root/abc/def/ggg  --> def/ggg
    public String relativePath(String rootAbsolutePath, String absolutePath) {
        String res = absolutePath.substring(rootAbsolutePath.length());
        res = res.replace(File.separatorChar, '/');

        return res;
    }
}
